home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / 3d.plo < prev    next >
Text File  |  1995-03-23  |  6KB  |  245 lines

  1. Article 5382 of comp.sys.handhelds:
  2. Newsgroups: comp.sys.handhelds
  3. Path: en.ecn.purdue.edu!eldorado
  4. From: eldorado@en.ecn.purdue.edu (David D Jansen)
  5. Subject: 3 Dimentional Graphing Program for the HP48
  6. Message-ID: <1991Mar29.210101.29112@en.ecn.purdue.edu>
  7. Keywords: 3D Graphing
  8. Organization: Purdue University Engineering Computer Network
  9. Date: Fri, 29 Mar 91 21:01:01 GMT
  10.  
  11.  
  12. Here is a 3 dimentional surface graphing program for the HP48SX.
  13.  
  14. Some features are:
  15. 1.  It doesn't go belly up if it encounters a divide by zero or
  16.         undefined result.
  17. 2.  It allows the domains of the XY plane to be defined to any value (
  18.         although it centers the plot on the origin).
  19. 3.  The equation is entered in X, Y, Z format not parametric form.
  20. 4.  It creates a matrix of the topology of the surface which is useful for
  21.         locating actual values of a max or min.
  22.  
  23. It is controlled by its own plot parameters which are stored in SPAR.  SPAR
  24. is defined as a list with the following elements:
  25. { lower X limit; upper X limit; X increment; lower Y limit; upper Y limit;
  26.     Y increment; angle of X with horizontal; angle of Y with horizontal;
  27.     flag signalling to plot a plane at Z; value of Z to plot plane;
  28.     X expansion factor; Y expansion factor }
  29.  
  30. The upper and lower X limit is the domain in the X coordinate.
  31. Likewise for the upper and lower Y limit.
  32.  
  33. The X and Y increments set how close together the points will be.
  34.  
  35. The angles allow the XY plane to change shape for better viewing.  If they
  36. are changed by the same amount for consecutive plots, the graph will seem 
  37. to rotate.  A type of rotation by 90 degrees can be done using the Translate
  38. command on the variable TOPO.  The Translate command is found in the Matrix
  39. directory.
  40.  
  41. The flag determining whether an XY plane should be plotted can have the
  42. values -1, 0, 1.  0 designates no plane plotted.  1 designates the surface
  43. will be plotted on top of the plane.  -1 draws the plane above the surface.
  44.  
  45. Z is the value one the Z axis (the altitude) at which the XY plane will
  46. be plotted.
  47.  
  48. The X and Y expansion factors scale the graph on the HP screen.
  49.  
  50. Directions
  51.  
  52. 1.  Enter your equation and store it in varible EQ
  53. 2.  Press the SFACE menu key
  54. 3.  Wait for the screen to draw and then press a key to end
  55. 4.  If you wish to change one of the parameters in SPAR, do so and then
  56.         choose TRACE since the topology of the EQ is known.  This means that
  57.         recalculation is not needed to review the graph.
  58. 5.  The topology and the actual graph are saved when done.
  59.  
  60. Enjoy.  Send comments, questions, complaints to:
  61. _______________________________________________________________________________
  62. Dave Jansen             |  INTERNET:  eldorado@en.ecn.purdue.edu
  63. Electrical Engineering  |  BITNET:    eldorado%ea.ecn.purdue.edu@purccvm
  64. Purdue University       |  UUCP:     {purdue, pur-ee}!en.ecn.purdue.edu!eldorado
  65.  
  66. %%HP: T(3)A(D)F(.);
  67. DIR
  68.   SFACE
  69.     \<< SPAR OBJ\->
  70. DROP 0 \-> xa xb xi
  71. ya yb yi theta phi
  72. p z h v d
  73.       \<< -20 -21 -22
  74. SF CF CF RAD ya yb
  75.         FOR J J 'Y'
  76. STO xa xb
  77.           FOR I I
  78. 'X' STO DEPTH 'd'
  79. STO
  80.             IFERR
  81. EQ \->NUM
  82.             THEN
  83. DEPTH d - DROPN 0
  84.             END
  85.             IF DUP
  86. TYPE 1 ==
  87.             THEN
  88. DROP 0
  89.             END yi
  90.           STEP xi
  91.         STEP yb ya
  92. - ABS 1 + xb xa -
  93. ABS 1 + 2 \->LIST
  94. \->ARRY 'TOPO' STO {
  95. X Y } PURGE DEG -20
  96. -21 -22 CF SF SF
  97. TRACE
  98.       \>>
  99.     \>>
  100.   TRACE
  101.     \<< SPAR OBJ\->
  102. DROP \-> xa xb xi ya
  103. yb yi theta phi p z
  104. h v
  105.       \<< 0 0 0 0 0 \->
  106. cphi sphi ctheta
  107. stheta prv
  108.         \<< PICT
  109. PURGE { # 0d # 0d }
  110. PVIEW AXIS RAD
  111. theta \pi * 180 /
  112. \->NUM DUP SIN
  113. 'stheta' STO COS
  114. 'ctheta' STO phi \pi
  115. * 180 / \->NUM DUP
  116. SIN 'sphi' STO COS
  117. 'cphi' STO ya yb
  118.           FOR j j
  119. cphi * xa ctheta *
  120. - h * 65 + 0 RND
  121. # 1d * 63 j NEG
  122. sphi * xa stheta *
  123. - v * 31 + 0 RND
  124. TOPO 1 j ya - yi *
  125. 1 + 2 \->LIST GET
  126.             IF p 0
  127. \=/
  128.             THEN
  129.               IF
  130. DUP DUP z < p 0 >
  131. AND SWAP z > p 0 <
  132. AND OR
  133.               THEN
  134. DROP z
  135.               END
  136.             END + -
  137. # 1d * 2 \->LIST
  138. 'prv' STO 1 xa + xb
  139.             FOR i
  140. prv j cphi * i
  141. ctheta * - h * 65 +
  142. 0 RND # 1d * 63 j
  143. NEG sphi * i stheta
  144. * - v * 31 + 0 RND
  145. TOPO i xa - xi * 1
  146. + j ya - yi * 1 + 2
  147. \->LIST GET
  148.               IF p
  149. 0 \=/
  150.               THEN
  151. IF DUP DUP z < p 0
  152. > AND SWAP z > p 0
  153. < AND OR
  154. THEN DROP z
  155. END
  156.               END +
  157. - # 1d * 2 \->LIST
  158. DUP 'prv' STO LINE
  159. xi
  160.             STEP yi
  161.           STEP xa
  162. xb
  163.           FOR i ya
  164. cphi * i ctheta * -
  165. h * 65 + 0 RND # 1d
  166. * 63 ya NEG sphi *
  167. i stheta * - v * 31
  168. + 0 RND TOPO i xa -
  169. xi * 1 + 1 2 \->LIST
  170. GET
  171.             IF p 0
  172. \=/
  173.             THEN
  174.               IF
  175. DUP DUP z < p 0 >
  176. AND SWAP z > p 0 <
  177. AND OR
  178.               THEN
  179. DROP z
  180.               END
  181.             END + -
  182. # 1d * 2 \->LIST
  183. 'prv' STO 1 ya + yb
  184.             FOR j
  185. prv j cphi * i
  186. ctheta * - h * 65 +
  187. 0 RND # 1d * 63 j
  188. NEG sphi * i stheta
  189. * - v * 31 + 0 RND
  190. TOPO i xa - xi * 1
  191. + j ya - yi * 1 + 2
  192. \->LIST GET
  193.               IF p
  194. 0 \=/
  195.               THEN
  196. IF DUP DUP z < p 0
  197. > AND SWAP z > p 0
  198. < AND OR
  199. THEN DROP z
  200. END
  201.               END +
  202. - # 1d * 2 \->LIST
  203. DUP 'prv' STO LINE
  204. yi
  205.             STEP xi
  206.           STEP DEG
  207. PICT RCL 'GRPH' STO
  208.           DO
  209.           UNTIL KEY
  210.           END DROP
  211.         \>>
  212.       \>>
  213.     \>>
  214.   EQ 'Y^2-X^2'
  215.   SPAR { -5 5 1 -5
  216. 5 1 30 45 0 0 5 3 }
  217.   AXIS
  218.     \<< SPAR OBJ\->
  219. DROP \-> xa xb xi ya
  220. yb yi theta phi p z
  221. h v
  222.       \<< DEG { # 65d
  223. # 32d } DUP DUP {
  224. # 65d # 0d } LINE
  225. 10 h * theta COS *
  226. NEG 65 + 0 RND # 1d
  227. * 63 10 v * theta
  228. SIN * NEG 31 + - 0
  229. RND # 1d * 2 \->LIST
  230. LINE 10 h * phi COS
  231. * 65 + 0 RND # 1d *
  232. 63 10 v * phi SIN *
  233. NEG 31 + - 0 RND
  234. # 1d * 2 \->LIST LINE
  235.       \>>
  236.     \>>
  237. END
  238. -- 
  239.  
  240. P.O.W. * M.I.A.  --  You are not forgotten
  241. _______________________________________________________________________________
  242. Dave Jansen             |  INTERNET:  eldorado@en.ecn.purdue.edu
  243.  
  244.  
  245.